<template>
    <div class="top">
        <div class="left">
            <span class="home" @click="goHome">首页</span>
        </div>
        <div class="center">
            <div class="title">可视化大数据展示平台</div>
        </div>
        <div class="right">
            <span class="report">统计报告</span>
            <span class="time">当前时间{{ time }}</span>
        </div>
    </div>
</template>

<script setup lang="ts" name="Top">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { useRouter } from 'vue-router';
import moment from 'moment';

const router = useRouter()
const goHome = () => {
    router.push('/home')
}

const time = ref(moment().format('YYYY年MM月DD日 HH:mm:ss'))

const timer = ref()
onMounted(() => {
    timer.value = setInterval(() => {
        time.value = moment().format('YYYY年MM月DD日 HH:mm:ss')
    }, 1000);
})

onBeforeUnmount(() => {
    clearInterval(timer.value)
})
</script>

<style scoped lang="scss">
.top {
    width: 100%;
    height: 40px;
    display: flex;

    .left {
        flex: 1.5;
        display: flex;
        justify-content: flex-end;

        .home {
            width: 150px;
            height: 40px;
            font-size: 20px;
            text-align: center;
            line-height: 40px;
            cursor: pointer;
        }
    }

    .center {
        flex: 2;

        .title {
            width: 100%;
            height: 74px;
            text-align: center;
            line-height: 74px;
            font-size: 30px;
        }
    }

    .right {
        flex: 1.5;
        display: flex;
        justify-content: space-between;
        align-items: center;


        .report {
            width: 150px;
            height: 40px;
            font-size: 20px;
            text-align: center;
            line-height: 40px;
            cursor: pointer;
        }

        .time {
            margin-right: 20px;
            font-size: 20px;
        }
    }
}
</style>